package com.kgc.service.impl;

import com.kgc.dao.TicketInfoMapper;
import com.kgc.dao.TicketInfoMapperEx;
import com.kgc.pojo.TicketInfoEx;
import com.kgc.pojo.TicketInfoExample;
import com.kgc.service.TicketInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class TicketInfoServiceImpl implements TicketInfoService {
    @Autowired
    private TicketInfoMapper ticketInfoMapper;
    @Autowired
    private TicketInfoMapperEx ticketInfoMapperEx;

    @Cacheable(value = "ticketInfo",key = "'getTicketInfoByClassify'+#pageNow+','+#pageSize+','+#cityId+','+#perfomTypeId+','+#startDate+','+#endDate")
    @Override
    public List<TicketInfoEx> getTicketInfoByClassify(Integer pageNow, Integer pageSize, Integer cityId, Integer perfomTypeId, Date startDate, Date endDate) {
        int start = (pageNow-1)*pageSize;
        return ticketInfoMapperEx.getTicketInfoByClassify(start,pageSize,cityId,perfomTypeId, startDate,endDate);
    }


    @Cacheable(value = "ticketInfo",key = "'getTicketInfoCount_yuan'+#perfomTypeId+','+#startDate+','+#endDate")
    @Override
    public int getTicketInfoCount_yuan(Integer cityId, Integer perfomTypeId, Date startDate,Date endDate) {
        TicketInfoExample ticketInfoExample = new TicketInfoExample();
        TicketInfoExample.Criteria criteria = ticketInfoExample.createCriteria();
        if (cityId != null){
            criteria.andCityidEqualTo(cityId);
        }
       if (perfomTypeId != null){
           criteria.andPerfomtypeidEqualTo(perfomTypeId);
       }
        if (startDate != null && endDate != null){
            criteria.andDateBetween(startDate,endDate);
        }
        return ticketInfoMapper.countByExample(ticketInfoExample);
    }


}